package com.xb.cloud.gateway.filter;

import java.util.ArrayList;
import java.util.List;

import com.xb.cloud.gateway.client.Context;

public class Test {
	public static void main(String[] args) {
		InboundFilter inboundFilter = new InboundFilter();
		List<GatewayFilter> filters = new ArrayList<>();
		filters.add(new AFilter());
		filters.add(new BFilter());
		filters.add(new CFilter());
		inboundFilter.setFilters(filters);
		Context xbContext = new Context(null, null, "", true, null, "", null);
		xbContext.setContentType("start");
		inboundFilter.doFilter(xbContext, null);
		System.out.println("end ----" + xbContext.getContentType());
	}

}

class AFilter implements GatewayFilter {
	@Override
	public void init() {
	}

	@Override
	public void doFilter(Context xbContext, GatewFilterChain chain) {
		System.out.println("A ----" + xbContext.getContentType());
		xbContext.setContentType("A");
		chain.doFilter(xbContext);
	}

	@Override
	public int filterOrder() {
		return 3;
	}

	@Override
	public void destroy() {
	}
}

class BFilter implements GatewayFilter {
	@Override
	public void init() {
	}

	@Override
	public void doFilter(Context xbContext, GatewFilterChain chain) {
		System.out.println("B----" + xbContext.getContentType());
		if (xbContext.isCheckToken()) {
			xbContext.setContentType("isCheckToken B");
		}
		chain.doFilter(xbContext);
	}

	@Override
	public int filterOrder() {
		return 1;
	}

	@Override
	public void destroy() {
	}
}

class CFilter implements GatewayFilter {
	@Override
	public void init() {
	}

	@Override
	public void doFilter(Context xbContext, GatewFilterChain chain) {
		System.out.println("C----" + xbContext.getContentType());
		xbContext.setContentType("C");
		chain.doFilter(xbContext);
	}

	@Override
	public int filterOrder() {
		return 0;
	}

	@Override
	public void destroy() {
	}
}